/*
 * @Author: Wilbur
 * @Date: 2019-04-29 14:52:43
 * @Last Modified by: Wilbur
 * @Last Modified time: 2019-04-29 15:41:42
 * 赞助结算列表页
 */

<template>
    <div class="container sponsor-settlement-list-container">
        <!-- <div class="operation-wrapper">
            <el-button
                type="primary"
                @click="handleRoute('bannerAdd')"
                size="small">新增轮播图</el-button>
        </div> -->
        <div class="content-wrapper">
            <div class="table-wrapper">
                <el-table
                    :data="tableData"
                    height="100%"
                    style="width: 100%;">
                    <el-table-column
                        fixed="left"
                        header-align="left"
                        align="center"
                        :width="50"
                        label="序号">
                        <template slot-scope="scope">
                            <div class="table-index">
                                {{ scope.$index + 1 }}
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column
                        fixed="left"
                        prop="title"
                        :min-width="120"
                        show-overflow-tooltip
                        label="活动名称"/>
                    <el-table-column
                        prop="sponsor_status"
                        show-overflow-tooltip
                        label="赞助状态">
                        <template slot-scope="scope">
                            <template v-if="scope.row.sponsor_status == 1">已赞助</template>
                            <template v-if="scope.row.sponsor_status == 2">赞助已结束</template>
                        </template>
                    </el-table-column>

                    <el-table-column
                        label="活动类型">
                        <template slot-scope="scope">
                            <template v-if="scope.row.type == 1">投票</template>
                            <template v-if="scope.row.type == 2">报名</template>
                            <template v-if="scope.row.type == 3">微信墙</template>
                            <template v-if="scope.row.type == 4">抢票</template>
                        </template>
                    </el-table-column>
                    <el-table-column
                        show-overflow-tooltip
                        prop="supply_phone"
                        :formatter="emptyFormatter"
                        label="联系方式"/>
                    <el-table-column
                        prop="activity_people_act_num"
                        show-overflow-tooltip
                        :min-width="105"
                        label="活动参与人数">>
                    </el-table-column>
                    <el-table-column
                        prop="hire_price"
                        label="单价(元)"/>
                    <el-table-column
                        prop="hire_money"
                        :min-width="105"
                        label="消耗金额(元)"/>
                    <el-table-column
                        prop="hire_info.company_name"
                        :formatter="emptyFormatter"
                        show-overflow-tooltip
                        label="赞助企业"/>
                    <el-table-column
                        prop="date"
                        label="操作"
                        fixed="right"
                        :width="80">
                        <template slot-scope="scope">
                            <div>
                                <el-button
                                    v-if="scope.row.sponsor_status == 1"
                                    type="text"
                                    @click="fnChangeSponsorStatus(scope.row.sponsor_no)">停止赞助</el-button>
                                <span v-else>--</span>
                            </div>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <div class="pagination-wrapper clearfix">
                <el-pagination
                    background
                    layout="total, prev, pager, next"
                    :total="page.total_count"
                    :page-size="page.page_size"
                    @current-change="getTableData" />
            </div>
        </div>
    </div>
</template>

<script>
import Clipboard from 'clipboard';
export default {
    data() {
        return {
            authResult: {},
            tableData: [],
            filterData: {
                title: ''
            },
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 0
            },
            baseUrl: '',
            mobileUrl: '',
            escape: escape,
            sessionTicket: localStorage.getItem('sessionTicket')
        };
    },
    created() {
        this.authResult = this.$route.meta.authResult;
        this.baseUrl = this.$baseUrl;
        this.mobileUrl = location.host == 'phaadmin.wxhand.com' ? 'http://class.zsdx.cn' : 'http://task.wxhand.com';
        this.$store.commit('SET_HEADER', [
            {
                title: "广告系统",
            },
            {
                title: '赞助结算'
            }
        ]);
        this.getTableData();
    },
    mounted() {
    },
    methods: {
        fnChangeSponsorStatus(sponsor_no) {
            this.$confirm('是否停止此赞助?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$post('/wei4/sponsor_activity%5Cstop_sponsor', {
                    sponsor_no: sponsor_no
                }, resp => {
                    if (resp.code == 1) {
                        this.getTableData(this.page.now_page);
                        this.$message({
                            type: 'success',
                            message: '操作成功',
                            center: true
                        });
                    }
                });
            }).catch(() => {
            });
        },
        /**
         * 复制链接
         */
        handleInitCopy(link) {
            var clipboard = new Clipboard('.copy-btn', {
                text: function () {
                    return link;
                }
            });

            clipboard.on('success', e => {
                this.$message({
                    type: 'success',
                    message: '复制成功'
                });
                e.clearSelection();
            });

            clipboard.on('error', e => {
                this.$message({
                    type: 'warning',
                    message: '未复制成功，请手动复制'
                });
            });
        },
        /**
         * 获取表格数据
         */
        getTableData(page) {
            this.$post('/wei4/sponsor_activity%5Cget_hire_sponsor_list', {
                page_id: page || this.page.now_page
            }, resp => {
                if (resp.code == 1) {
                    this.tableData = resp.data.list;
                    this.page.now_page = resp.data.page.now_page;
                    this.page.total_count = resp.data.page.total_count;
                    this.page.page_size = resp.data.page.page_size;
                }
            });
        },

        /**
         * 跳转页面
         */
        handleRoute(name, query) {
            let obj = {
                name
            };

            if (query) {
                obj.query = query;
            }

            this.$router.push(obj);
        },

        /**
         * 列表渲染辅助函数：列表项为空处理
         */
        emptyFormatter(row, column, val) {
            if (!val) {
                return '--';
            }
            return val;
        }
    }
};
</script>

<style lang="less" scoped>
.container {
    display: flex;
    flex-direction: column;
    width: 100%;
}
.operation-wrapper {
    display: flex;
    flex-direction: row-reverse;
    padding: 12px 23px;
    background-color: #fff;

    .el-button {
        margin-left: 10px;
    }
}
.content-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    margin: 15px;
    overflow: hidden;
}
.search-wrapper {
    padding: 15px;
    background-color: #fff;
}
.filter-item {
    .el-form-item {
        margin-bottom: 0;
        white-space: nowrap;
    }
    .el-input {
        width: auto;
        vertical-align: middle;
    }
    .el-button {
        margin-left: 15px;
        vertical-align: middle;
    }
}
.table-wrapper {
    flex: 1;
    background-color: #fff;
    .table-image{
        width: 150px;
    }
    .table-link{
        color: #409EFF;
    }
    .el-button {
        padding: 0;
    }
    .icon-bianji{
        font-size: 14px;
        color: #B9B9B9;
        cursor: pointer;
    }
    .btn-delete {
        color: #fd4d32;
        &.is-disabled {
            color: #c0c4cc;
            cursor: not-allowed;
        }
    }
    .submit-config-item {
        display: inline-block;
        position: relative;
        padding-right: 10px;
        font-size: 14px;

        & + .submit-config-item {
            padding-left: 10px;
            &::before {
                content: '';
                position: absolute;
                top: 50%;
                left: 0;
                width: 1px;
                height: 14px;
                transform: translate(0, -50%);
                background-color: #d8d8d8;
            }
        }

        .num {
            vertical-align: middle;
        }
        .iconfont {
            font-size: 16px;
            color: #b9b9b9;
            vertical-align: middle;
        }

        .icon-tupian {
            font-size: 20px;
        }
    }
}
.pagination-wrapper {
    padding-top: 10px;
    .el-pagination {
        float: right;
        padding: 0;
        background-color: transparent;
    }
}
.dialog-link{
    & + .dialog-link{
        margin-top: 20px;
    }
    .link-label{
        font-weight: 500;
        margin-right: 20px;
    }
    .link-value{
    }
}
</style>
<style lang="less">
.sponsor-settlement-list-container {
    tbody {
        .cell {
            display: flex;
            align-items: center;
            height: 48px;
        }
    }
}
.sponsor-settlement-list-preview-popover {
    min-width: auto!important;
    width: 120px!important;
    height: 120px;
    padding: 8px!important;
}
.sort-dialog{
    width: 270px!important;
}
</style>
